﻿///////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2008-2009 David Hill. All rights reserved.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
///////////////////////////////////////////////////////////////////////////////
using System;

using TFSBranchVisualizer.BranchVisualizer.Models;
using Infrastructure.TFSServiceClient;
using Infrastructure;

namespace TFSBranchVisualizer.BranchVisualizer.Services
{
    /// <summary>
    /// Dummy data service class. Provides a dummy data model.
    /// Replace with your real data model and/or data service proxy.
    /// </summary>
    public class DataService : IDataService
    {
        private TFSServiceClient _serviceInstance;

        public event EventHandler<BranchLoadingEventArgs> BranchLoadingComplete;
        public event EventHandler<BranchLoadingErrorEventArgs> BranchLoadingError;

        public DataService()
        {
            _serviceInstance = TFSServiceWrapper.Instance.ServiceClient;
        }

        public void GetBranches(string projectName)
        {
            try
            {
                _serviceInstance.GetProjectBranchesCompleted += new EventHandler<GetProjectBranchesCompletedEventArgs>(ServiceClient_GetProjectBranchesCompleted);
                _serviceInstance.GetProjectBranchesAsync(projectName);
            }
            catch (Exception ex)
            {
                if (BranchLoadingError != null)
                    BranchLoadingError(this, new BranchLoadingErrorEventArgs(ex));
            }
        }

        void ServiceClient_GetProjectBranchesCompleted(object sender, GetProjectBranchesCompletedEventArgs e)
        {
            if (BranchLoadingComplete != null)
                BranchLoadingComplete(this, new BranchLoadingEventArgs(e.Result));
        }
    }
}
